#pragma once
#include<iostream>
#include<signal.h>
#include"TcpServer.hpp"
#include"Log.hpp"
#include"Task.hpp"
#include"ThreadPool.hpp"
#define PORT 8080
class HttpServer
{
   private:
   int port;
   bool stop;
   public:
   HttpServer(int _port=PORT):port(_port),stop(false)
   {}
   void InitServer()
   {
      signal(SIGPIPE,SIG_IGN);
   }
   void Loop()
   {
      LOG(INFO,"Loop begin");
      TcpServer* tsvr=TcpServer::getinstance(port);
      while(!stop)
      {
        struct sockaddr_in peer;
        socklen_t len=sizeof(peer);
        std::cout<<"进入while啦----------"<<std::endl;
        int sockk=accept(tsvr->Sock(),(sockaddr*)&peer,&len);
        std::cout<< "hhhhhh" << std::endl;
        LOG(INFO,"Accept begin");
        if(sockk<0)
        {
             std::cout<<"accept接受失败啦"<<std::endl;
             continue;
        }
         LOG(INFO,"Get a new Link");
        std::cout << "accept接受成功啦" << std::endl;
        Task task(sockk);
        ThreadPool::getinstance()->PushTask(task);
      }
   }
   ~HttpServer()
   {}
};